#-*-coding:utf-8-*-
import pyttsx3 as pt3

def use_pyttsx3(words,audio_file):
    # 创建对象
    rob = pyttsx3.init()
    # 获取当前语音速率
    rate = rob.getProperty('rate')
    # 设置新的语音速率
    rob.setProperty('rate', 150)
    print(f'语音速率：{rate}')
    # 获取当前语音音量
    volume = rob.getProperty('volume')
    # 设置新的语音音量，音量最小为 0，最大为 1
    rob.setProperty('volume', 1.0)
    print(f'语音音量：{volume}')
    # 获取当前语音声音的详细信息
    voices = rob.getProperty('voices')
    #for _v in voices:
    #    print(f' id:{_v.id} \n name:{_v.name}')
    # 设置当前语音声音为，当前声音不能读中文
    #rob.setProperty('voice', voices[1].id)
    # 设置当前语音声音为，当前声音可以读中文
    rob.setProperty('voice', voices[0].id)
    #print(f'语音声音详细信息：{voices}')
    # 获取当前语音声音
    voice = rob.getProperty('voice')
    print(f'语音声音：{voice}')
    # 语音文本
    #path = 'test.txt'
    #with open(path, encoding='utf-8') as f_name:
    #    words = str(f_name.readlines()).replace(r'\n', '')
    # 将语音文本说出来
    #rob.say(words)
    #rob.save_to_file(words,audio_file)
    rob.runAndWait()
    rob.stop()





rob = pt3.init()
rob.say('visual studio code')
#rob.save_to_file('你好世界！','./msg.mp3')
rob.runAndWait()